//
//  CommentFrame.m
//  SinaWeibo
//
//  Created by mj on 13-8-30.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import "BaseTextFrame.h"
#import "BaseTextModel.h"
#import "AyIconView.h"
#import "AyUser.h"
#import "AyDefine.h"

@implementation BaseTextFrame
- (void)setTextModel:(BaseTextModel *)textModel
{
    _textModel = textModel;
    
    // 1.昵称
    CGFloat screenNameX = 2 * kCommentMargin + [AyIconView sizeWithIconType:IWIconTypeSmall].width;
    CGFloat screenNameY = kCommentMargin;
    CGSize screenNameSize = [textModel.user.name sizeWithFont:kScreenNameFont];
    _screenNameFrame = (CGRect){{screenNameX, screenNameY}, screenNameSize};
    
    // 2.会员
    CGFloat mbX = CGRectGetMaxX(_screenNameFrame) + kCommentMargin;
    CGFloat mbY = CGRectGetMidY(_screenNameFrame) - kMBHeight * 0.5;
    _mbFrame = CGRectMake(mbX, mbY, kMBWidth, kMBHeight);
    
    CGFloat cellWidth = [UIScreen mainScreen].bounds.size.width - 2 * kCommentMargin;
    
    // 3.文字
    CGFloat textX = screenNameX;
    CGFloat textY = kCommentMargin + CGRectGetMaxY(_screenNameFrame);
    CGSize textSize = [textModel.text sizeWithFont:kTextFont constrainedToSize:CGSizeMake(cellWidth - kCommentMargin - textX, MAXFLOAT)];
    _textFrame = (CGRect){{textX, textY}, textSize};
    
    // 4.cell的高度
    _cellHeight = CGRectGetMaxY(_textFrame) + 2 * kCommentMargin + kTimeFont.lineHeight;
}
@end
